Conditions | 1 |
Paths | 1 |
Total Lines | 248 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 3 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var chai = require('chai'); |
||
18 | describe('cmsTemplates.prepare', function() { |
||
19 | before( function(done) { |
||
20 | Manager.instance.init() |
||
21 | .then(function () { |
||
22 | this.fixture = { |
||
23 | visibleTrue: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-visible-true.html'), 'utf-8'), |
||
24 | visibleFalse: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-visible-false.html'), 'utf-8'), |
||
25 | text: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-text.html'), 'utf-8'), |
||
26 | attribute: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute.html'), 'utf-8'), |
||
27 | attributeConcat: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute-concat.html'), 'utf-8'), |
||
28 | attributeMultiple: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute-multiple.html'), 'utf-8'), |
||
29 | source: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-source.html'), 'utf-8'), |
||
30 | each: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each.html'), 'utf-8'), |
||
31 | eachMultiple: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each-multiple.html'), 'utf-8'), |
||
32 | eachVariable: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each-variable.html'), 'utf-8'), |
||
33 | rawHandlebar: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-raw-handlebars.html'), 'utf-8'), |
||
34 | noHtml: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-nohtml.html'), 'utf-8') |
||
35 | } |
||
36 | done() |
||
37 | |||
38 | }.bind(this)) |
||
39 | }); |
||
40 | |||
41 | /** |
||
42 | * cmsTemplates.template.addAbeDataAttrForHtmlTag |
||
43 | * |
||
44 | */ |
||
45 | it('cmsTemplates.prepare.addAbeDataAttrForHtmlTag()', function() { |
||
46 | // stub |
||
47 | |||
48 | // test |
||
49 | var template = cmsTemplates.prepare.addAbeDataAttrForHtmlTag(this.fixture.text) |
||
50 | chai.expect(template.indexOf('<span data-abe-text_visible="text_visible" >')).to.be.above(-1); |
||
51 | |||
52 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlTag(this.fixture.each) |
||
53 | chai.expect(template.indexOf('data-abe-test{{@index}}-title="test{{@index}}-title"')).to.be.above(-1) |
||
54 | |||
55 | // |
||
56 | try{ |
||
57 | template = cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags(this.fixture.noHtml) |
||
58 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlTag(template) |
||
59 | } catch (e) { |
||
60 | console.log(e.stack) |
||
|
|||
61 | } |
||
62 | chai.expect(template.indexOf('"<abe data-abe-stores{{@index}}-lat="stores{{@index}}-lat"')).to.be.above(-1) |
||
63 | chai.expect(template.indexOf('<abe data-abe-stores2{{@index}}-lat="stores2{{@index}}-lat" >')).to.be.above(-1) |
||
64 | chai.expect(template.indexOf('<abe data-abe-text2="text2" >{{abe type="text" key="text2" desc="name"}}</abe>')).to.be.above(-1) |
||
65 | chai.expect(template.indexOf('"<abe data-abe-text3="text3" >{{abe type="text" key="text3" desc="name"}}</abe>"')).to.be.above(-1) |
||
66 | }); |
||
67 | |||
68 | /** |
||
69 | * cmsTemplates.template.getAbeAttributeData |
||
70 | * |
||
71 | */ |
||
72 | it('cmsTemplates.prepare.getAbeAttributeData()', function() { |
||
73 | // stub |
||
74 | |||
75 | // test |
||
76 | var template = cmsTemplates.prepare.getAbeAttributeData( |
||
77 | this.fixture.attribute, |
||
78 | "src=\"{{abe type='image' key='image_key' tab='default'}}\"", |
||
79 | "src", |
||
80 | "{{abe type='image' key='image_key' tab='default'}}" |
||
81 | ) |
||
82 | chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
||
83 | }); |
||
84 | |||
85 | /** |
||
86 | * cmsTemplates.template.addHasAbeAttr |
||
87 | * |
||
88 | */ |
||
89 | it('cmsTemplates.prepare.addHasAbeAttr()', function() { |
||
90 | // stub |
||
91 | |||
92 | // test |
||
93 | var template = cmsTemplates.prepare.addHasAbeAttr("}}") |
||
94 | chai.expect(template.indexOf('has-abe=1}}')).to.be.above(-1); |
||
95 | }); |
||
96 | |||
97 | /** |
||
98 | * cmsTemplates.template.addAbeDataAttrForHtmlAttributes |
||
99 | * |
||
100 | */ |
||
101 | it('cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes()', function() { |
||
102 | // stub |
||
103 | |||
104 | // test |
||
105 | var template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attribute) |
||
106 | chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
||
107 | |||
108 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attributeConcat) |
||
109 | chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
||
110 | |||
111 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attributeMultiple) |
||
112 | chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
||
113 | chai.expect(template.indexOf('data-abe-attr-alternate="alt" data-abe-alternate="alternate" alt="mon alt')).to.be.above(-1); |
||
114 | |||
115 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.each) |
||
116 | chai.expect(template.indexOf('data-abe-attr-test[index].img="src" data-abe-test[index].img="test[index].img" data-abe-attr-test{{@index}}.img="src" data-abe-test{{@index}}.img="test[index].img" src="')).to.be.above(-1); |
||
117 | |||
118 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.eachMultiple) |
||
119 | chai.expect(template.indexOf('data-abe-attr-test[index].img="src" data-abe-test[index].img="test[index].img" data-abe-attr-test{{@index}}.img="src" data-abe-test{{@index}}.img="test[index].img" src="')).to.be.above(-1); |
||
120 | chai.expect(template.indexOf('data-abe-attr-test[index].alternate="alt" data-abe-test[index].alternate="test[index].alternate" data-abe-attr-test{{@index}}.alternate="alt" data-abe-test{{@index}}.alternate="test[index].alternate" alt="')).to.be.above(-1); |
||
121 | }); |
||
122 | |||
123 | /** |
||
124 | * cmsTemplates.template.addAbeSourceComment |
||
125 | * |
||
126 | */ |
||
127 | it('cmsTemplates.prepare.addAbeSourceComment()', function() { |
||
128 | var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.source, |
||
129 | { |
||
130 | abe_source: { |
||
131 | data_key: [{title: "test"}] |
||
132 | } |
||
133 | } |
||
134 | ) |
||
135 | |||
136 | chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
||
137 | chai.expect(template.indexOf('-->')).to.be.above(-1); |
||
138 | }); |
||
139 | |||
140 | it('cmsTemplates.prepare.addAbeSourceComment() each', function() { |
||
141 | var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.each, { |
||
142 | abe_source: { |
||
143 | test: [{title: "test"}] |
||
144 | } |
||
145 | }) |
||
146 | |||
147 | chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
||
148 | chai.expect(template.indexOf('-->')).to.be.above(-1); |
||
149 | chai.expect(template.indexOf('data-abe-block="test{{@index}}"')).to.be.above(-1) |
||
150 | }); |
||
151 | |||
152 | it('cmsTemplates.prepare.addAbeSourceComment() eachMultiple', function() { |
||
153 | var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.eachMultiple, { |
||
154 | abe_source: { |
||
155 | test: [{title: "test"}] |
||
156 | } |
||
157 | }) |
||
158 | |||
159 | chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
||
160 | chai.expect(template.indexOf('-->')).to.be.above(-1); |
||
161 | chai.expect(template.indexOf('data-abe-block')).to.be.above(-1) |
||
162 | }); |
||
163 | |||
164 | it('cmsTemplates.prepare.addAbeSourceComment() eachVariable', function() { |
||
165 | var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.eachVariable, { |
||
166 | abe_source: { |
||
167 | test: [{title: "test"}] |
||
168 | } |
||
169 | }) |
||
170 | |||
171 | chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
||
172 | chai.expect(template.indexOf('-->')).to.be.above(-1); |
||
173 | }); |
||
174 | |||
175 | /** |
||
176 | * cmsTemplates.template.addAbeHtmlTagBetweenAbeTags |
||
177 | * |
||
178 | */ |
||
179 | it('cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags()', function() { |
||
180 | // stub |
||
181 | |||
182 | // test |
||
183 | var template = cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags(this.fixture.text) |
||
184 | chai.expect(template.indexOf('<abe>{{')).to.be.above(-1); |
||
185 | chai.expect(template.indexOf('}}</abe>')).to.be.above(-1); |
||
186 | |||
187 | template = cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags(this.fixture.noHtml) |
||
188 | chai.expect(template.indexOf('"lat": "<abe>{{abe type="text" key="stores.lat" desc="lat"}}</abe>"')).to.be.above(-1) |
||
189 | chai.expect(template.indexOf('<abe>{{abe type="text" key="stores2.lat" desc="lat"}}</abe>')).to.be.above(-1) |
||
190 | chai.expect(template.indexOf('<abe>{{abe type="text" key="text2" desc="name"}}</abe>')).to.be.above(-1) |
||
191 | chai.expect(template.indexOf('"<abe>{{abe type="text" key="text3" desc="name"}}</abe>"')).to.be.above(-1) |
||
192 | |||
193 | }); |
||
194 | |||
195 | /** |
||
196 | * cmsTemplates.template.replaceAbeEachIndex |
||
197 | * |
||
198 | */ |
||
199 | it('cmsTemplates.prepare.replaceAbeEachIndex()', function() { |
||
200 | var template = cmsTemplates.prepare.replaceAbeEachIndex('[index].') |
||
201 | chai.expect(template).to.be.equal('{{@index}}-'); |
||
202 | }); |
||
203 | |||
204 | /** |
||
205 | * cmsTemplates.template.removeHiddenAbeTag |
||
206 | * |
||
207 | */ |
||
208 | it('cmsTemplates.prepare.removeHiddenAbeTag()', function() { |
||
209 | var template = cmsTemplates.prepare.removeHiddenAbeTag(this.fixture.visibleFalse) |
||
210 | chai.expect(template).to.be.equal(""); |
||
211 | |||
212 | var template2 = cmsTemplates.prepare.removeHiddenAbeTag(this.fixture.visibleTrue) |
||
213 | chai.expect(template2.indexOf('{{abe')).to.be.above(-1); |
||
214 | }); |
||
215 | |||
216 | /** |
||
217 | * cmsTemplates.template.removeHandlebarsRawFromHtml |
||
218 | * |
||
219 | */ |
||
220 | it('cmsTemplates.prepare.removeHandlebarsRawFromHtml()', function() { |
||
221 | var template = cmsTemplates.prepare.removeHandlebarsRawFromHtml(this.fixture.rawHandlebar) |
||
222 | chai.expect(template).to.be.equal("test"); |
||
223 | }); |
||
224 | |||
225 | /** |
||
226 | * cmsTemplates.template.splitEachBlocks |
||
227 | * |
||
228 | */ |
||
229 | it('cmsTemplates.prepare.splitEachBlocks()', function() { |
||
230 | var blocks = cmsTemplates.prepare.splitEachBlocks(this.fixture.each) |
||
231 | chai.expect(blocks.length).to.be.above(0); |
||
232 | }); |
||
233 | |||
234 | /** |
||
235 | * cmsTemplates.template.indexEachBlocks |
||
236 | * |
||
237 | */ |
||
238 | it('cmsTemplates.prepare.indexEachBlocks() each', function() { |
||
239 | var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.each, false) |
||
240 | chai.expect(template.indexOf('abe dictionnary=')).to.be.above(-1) |
||
241 | }); |
||
242 | |||
243 | it('cmsTemplates.prepare.indexEachBlocks() eachMultiple', function() { |
||
244 | var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.eachMultiple, false) |
||
245 | chai.expect(template.indexOf('abe dictionnary=')).to.be.above(-1) |
||
246 | }); |
||
247 | |||
248 | it('cmsTemplates.prepare.indexEachBlocks() eachVariable', function() { |
||
249 | var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.eachVariable, false) |
||
250 | chai.expect(template.indexOf('abe dictionnary=')).to.be.above(-1) |
||
251 | chai.expect(template.indexOf('{{formatted_address}} - (lat:{{geometry.location.lat}}-lng:{{geometry.location.lng}})')).to.be.above(-1) |
||
252 | }); |
||
253 | |||
254 | /** |
||
255 | * cmsTemplates.template.addAbeDictionnary |
||
256 | * |
||
257 | */ |
||
258 | it('cmsTemplates.prepare.addAbeDictionnary()', function() { |
||
259 | // stub |
||
260 | |||
261 | // test |
||
262 | var template = cmsTemplates.prepare.addAbeDictionnary(this.fixture.each, "{{abe type='text' key='test.title' desc='test title' tab='default'}}", 'test') |
||
263 | chai.expect(template.indexOf("abe dictionnary='test'")).to.be.above(-1); |
||
264 | }); |
||
265 | }); |
||
266 |